package bin_tree.leetcode;

/**
 * @author yuisama
 * @date 2023/03/24 19:43
 * 翻转二叉树
 **/
public class Num226_InvertTree {
    public TreeNode invertTree(TreeNode root) {
        // base case
        if(root == null || root.left == null && root.right == null) {
            return root;
        }
        // 先递归的翻转左子树
        root.left = invertTree(root.left);
        // 再递归的翻转右子树
        root.right = invertTree(root.right);
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
        return root;
    }
}